package com.springchang.leetcode.array;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * 第一题
 */
public class DivideArrayTopairs {

    public static boolean divideArray(int[] nums) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int num : nums) {
            if(map.containsKey(num)) {
                map.put(num, map.get(num)+1);
            } else {
                map.put(num, 1);
            }
        }

        Iterator<Map.Entry<Integer, Integer>> iterator = map.entrySet().iterator();
        while(iterator.hasNext()) {
            Map.Entry<Integer, Integer> entry = iterator.next();
            if(entry.getValue()%2 != 0) {
                return false;
            }
        }

        return true;
    }

    public static void main(String[] args) {
        int[] nums = new int[]{3,2,3,2,2,2};
        System.out.println(divideArray(nums));
    }
}
